<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="120px">
			<el-form-item label="档案区编号" prop="archAreaNo">
				<el-input v-model="queryParams.archAreaNo" placeholder="请输入档案区编号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="档案柜ip" prop="cabinetIp">
				<el-input v-model="queryParams.cabinetIp" placeholder="请输入档案柜ip" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<!-- <el-form-item label="档案室编号" prop="archivesRoomNo">
        <el-input
          v-model="queryParams.archivesRoomNo"
          placeholder="请输入档案室编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item> -->
			<el-form-item label="开柜方向" prop="openDirection">
				<!--        <el-input-->
				<!--          v-model="queryParams.openDirection"-->
				<!--          placeholder="请输入开柜方向"-->
				<!--          clearable-->
				<!--          @keyup.enter="handleQuery"-->
				<!--        />-->
				<el-select v-model="queryParams.openDirection" placeholder="请选择开柜方向">
					<el-option v-for="dict in open_direction" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="档案类型" prop="archType">
				<el-select v-model="queryParams.archType" placeholder="请选择档案类型">
					<el-option v-for="dict in archive_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
				<el-button icon="Refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['archive:ArchiveArchArea:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['archive:ArchiveArchArea:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['archive:ArchiveArchArea:remove']"
        >删除</el-button>
      </el-col> -->
			<!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['archive:ArchiveArchArea:export']"
        >导出</el-button>
      </el-col> -->
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="ArchiveArchAreaList" @selection-change="handleSelectionChange">
			<!-- <el-table-column type="selection" width="55" align="center" /> -->
			<!-- <el-table-column label="序号" align="center" prop="id" /> -->
			<el-table-column label="档案区编号" align="center" prop="archAreaNo" />
			<el-table-column label="档案类型" align="center" prop="archType" width="300px">
			</el-table-column>
			<!-- <el-table-column label="档案室编号" align="center" prop="archivesRoomNo" /> -->
			<el-table-column label="开柜方向" align="center" prop="openDirection">
				<template #default="scope">
					<dict-tag :options="open_direction" :value="scope.row.openDirection" />
				</template>
			</el-table-column>
			<el-table-column label="状态" align="center" prop="status">
				<template #default="scope">
					<dict-tag :options="area_status" :value="scope.row.status" />
				</template>
			</el-table-column>
			<el-table-column label="档案柜ip" align="center" prop="cabinetIp" />
			<el-table-column label="告警信息" align="center" prop="message" />
			<!--      <el-table-column label="创建时间" align="center" prop="createTime" width="180">-->
			<!--        <template #default="scope">-->
			<!--          <span>{{ parseTime(scope.row.createTime) }}</span>-->
			<!--        </template>-->
			<!--      </el-table-column>-->
			<el-table-column label="操作" align="center" fixed="right" width="200">
				<template #default="scope">
					<!--          <el-button-->
					<!--            type="text"-->
					<!--            icon="Edit"-->
					<!--            @click="handleUpdate(scope.row)"-->
					<!--            v-hasPermi="['archive:ArchiveArchArea:edit']"-->
					<!--          >修改</el-button>-->
					<!--          <el-button-->
					<!--            type="text"-->
					<!--            icon="Delete"-->
					<!--            @click="handleDelete(scope.row)"-->
					<!--            v-hasPermi="['archive:ArchiveArchArea:remove']"-->
					<!--          >删除</el-button>-->
					<el-button type="text" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['archive:ArchiveArchArea:edit']">设置</el-button>
				</template>
			</el-table-column>

		</el-table>

		<pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
		 @pagination="getList" />

		<!-- 添加或修改区对话框 -->
		<el-dialog :title="title" v-model="open" width="500px" append-to-body>
			<el-form ref="ArchiveArchAreaRef" :model="form" :rules="rules" label-width="120px">
				<el-form-item label="档案区编号" prop="archAreaNo">
					<el-input v-model="form.archAreaNo" placeholder="请输入档案区编号" disabled="disabled" style="width:280px" />
				</el-form-item>
				<!--  <el-form-item label="档案区名称" prop="arhcAreaName">
          <el-input v-model="form.arhcAreaName" placeholder="请输入档案区名称" disabled="disabled" style="width:280px"/>
        </el-form-item>
        <el-form-item label="档案类型" align="center" prop="archType" >
          <el-select v-model="form.archType" placeholder="请选择档案类型" disabled="disabled" style="width:280px">
            <el-option v-for="dict in area_archive_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
          </el-select>
        </el-form-item> -->
				<el-form-item label="开柜方向" prop="openDirection">
					<el-select v-model="form.openDirection" placeholder="请选择开柜方向" style="width:280px">
						<el-option v-for="dict in open_direction" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
					</el-select>
				</el-form-item>
				<!--        <el-form-item label="档案室编号" prop="archivesRoomNo">-->
				<!--          <el-input v-model="form.archivesRoomNo" placeholder="请输入档案室编号" />-->
				<!--        </el-form-item>-->
				<el-form-item label="档案柜ip" prop="cabinetIp">
					<el-input v-model="form.cabinetIp" placeholder="请输入档案柜ip" style="width:280px" maxlength="50" />
				</el-form-item>

			</el-form>
			<template #footer>
				<div class="dialog-footer">
					<el-button type="primary" @click="submitForm">确 定</el-button>
					<el-button @click="cancel">取 消</el-button>
				</div>
			</template>
		</el-dialog>
	</div>
</template>

<script setup name="ArchiveArchArea">
	import {
		listArchiveArchArea,
		getArchiveArchArea,
		delArchiveArchArea,
		addArchiveArchArea,
		updateArchiveArchArea
	} from "@/api/archive/ArchiveArchArea";
	import {
		getCurrentInstance,
		reactive,
		ref,
		toRefs
	} from "vue";
	const {
		proxy
	} = getCurrentInstance();

	const ArchiveArchAreaList = ref([]);
	const open = ref(false);
	const loading = ref(true);
	const showSearch = ref(true);
	const ids = ref([]);
	const single = ref(true);
	const multiple = ref(true);
	const total = ref(0);
	const title = ref("");

	const data = reactive({
		form: {},
		queryParams: {
			pageNum: 1,
			pageSize: 10,
			archAreaNo: null,
			arhcAreaName: null,
			archType: null,
			archivesRoomNo: null,
			openDirection: null,
			cabinetIp: null,
		},
		rules: {}
	});

	const {
		queryParams,
		form,
		rules
	} = toRefs(data);
	const {
		area_archive_type,
		open_direction,
		area_status,
		archive_type
	} = proxy.useDict('area_archive_type', 'open_direction', 'area_status','archive_type');

	/** 查询区列表 */
	function getList() {
		loading.value = true;
		listArchiveArchArea(queryParams.value).then(response => {
			ArchiveArchAreaList.value = response.rows;
			total.value = response.total;
			loading.value = false;
		});
	}

	// 取消按钮
	function cancel() {
		open.value = false;
		reset();
	}

	// 表单重置
	function reset() {
		form.value = {
			id: null,
			archAreaNo: null,
			arhcAreaName: null,
			archType: null,
			archivesRoomNo: null,
			openDirection: null,
			createTime: null,
			creator: null,
			modifyTime: null,
			modifier: null
		};
		proxy.resetForm("ArchiveArchAreaRef");
	}

	/** 搜索按钮操作 */
	function handleQuery() {
		queryParams.value.pageNum = 1;
		getList();
	}

	/** 重置按钮操作 */
	function resetQuery() {
		proxy.resetForm("queryRef");
		handleQuery();
	}

	// 多选框选中数据
	function handleSelectionChange(selection) {
		ids.value = selection.map(item => item.id);
		single.value = selection.length != 1;
		multiple.value = !selection.length;
	}

	/** 新增按钮操作 */
	function handleAdd() {
		reset();
		open.value = true;
		title.value = "添加档案区";
	}

	/** 修改按钮操作 */
	function handleUpdate(row) {
		reset();
		const id = row.id || ids.value
		getArchiveArchArea(id).then(response => {
			form.value = response.data;
			open.value = true;
			title.value = "修改档案区";
		});
	}

	/** 提交按钮 */
	function submitForm() {
		proxy.$refs["ArchiveArchAreaRef"].validate(valid => {
			if (valid) {
				if (form.value.id != null) {
					updateArchiveArchArea(form.value).then(response => {
						proxy.$modal.msgSuccess("修改成功");
						open.value = false;
						getList();
					});
				} else {
					addArchiveArchArea(form.value).then(response => {
						proxy.$modal.msgSuccess("新增成功");
						open.value = false;
						getList();
					});
				}
			}
		});
	}

	/** 删除按钮操作 */
	function handleDelete(row) {
		const id = row.id || ids.value;
		proxy.$modal.confirm('是否确认删除区编号为"' + id + '"的数据项？').then(function() {
			return delArchiveArchArea(ids);
		}).then(() => {
			getList();
			proxy.$modal.msgSuccess("删除成功");
		}).catch(() => {});
	}

	/** 导出按钮操作 */
	function handleExport() {
		proxy.download('archive/ArchiveArchArea/export', {
			...queryParams.value
		}, `档案区_${new Date().getTime()}.xlsx`)
	}

	getList();
</script>
